<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
use Common\Model\CaozuologModel;
use Common\Logic\ImageLogic;
class BannerController extends AdminController{
	public function _initialize(){
		parent::_initialize();
	}
	public function index(){
		$list=M('Banner')->order('sort asc')->select();
		$data['list']=$list;
		$data['status']=1;
		$this->ajaxReturn($data);
	}
	public function add(){
			$pic=I('pic');
			if(empty($pic)){
				$data_return['status'] = -5;
				$data_return['info'] = '请上传图片';
				$this->ajaxReturn($data_return);
			}
			$arr['status']=1;
			$arr['pic']=$pic;
			$arr['add_time']=time();
			$a=M('Banner')->add($arr);
			if($a){
				$data = [
				'status'=>1,
				'msg'=>'操作成功'
				];
				$M_LOG = new CaozuologModel();
				$content = '新增轮播图';
				$M_LOG->addLog($this->user['username'], $content);
				$this->ajaxReturn($data);
			}else{
				$data = [
				'status'=>-1,
				'msg'=>'服务器繁忙'
				];
				$this->ajaxReturn($data);
			}			
		
	}
	public function update(){
		$id=I('id');
		$banner=M('banner')->where('id ='.$id)->find();
		if(!$banner){
			$data = [
			'status'=>-1,
			'msg'=>'参数错误'
					];
			$this->ajaxReturn($data);
		}
		$pic=I('pic');
		$arr['pic']=$pic;
		$a=M('Banner')->where('id ='.$id)->save($arr);
		if($a){
			$data = [
			'status'=>1,
			'msg'=>'操作成功'
					];
			$M_LOG = new CaozuologModel();
			$content = '修改轮播图';
			$M_LOG->addLog($this->user['username'], $content);
			$this->ajaxReturn($data);
		}else{
			$data = [
			'status'=>-1,
			'msg'=>'服务器繁忙'
					];
			$this->ajaxReturn($data);
		}
			
	}
	public function del(){
		$id=I('id');
		$banner=M('banner')->where('id ='.$id)->find();
		if(!$banner){
			$data = [
			'status'=>-1,
			'msg'=>'参数错误'
					];
			$this->ajaxReturn($data);
		}
		$r=M('banner')->where('id ='.$id)->delete();
		if(!$r){
			$data = [
			'status'=>-1,
			'msg'=>'服务器繁忙'
					];
			$this->ajaxReturn($data);
		}
		$data = [
		'status'=>1,
		'msg'=>'删除成功'
				];
		$M_LOG = new CaozuologModel();
		$content = '删除轮播图';
		$M_LOG->addLog($this->user['username'], $content);
		$this->ajaxReturn($data);
	}
}